﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Taxes.DAL
{
	/// <summary>
	/// 数据访问类:tax_info
	/// </summary>
	public partial class tax_info
	{
		public tax_info()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("ID", "tax_info"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from tax_info");
			strSql.Append(" where ID=@ID");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)
};
			parameters[0].Value = ID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}
        public bool up_setTaxInfo(string compute_code, string tax_ny, int tax_type, decimal tax_money)
        {
            int result = 0;
            SqlParameter[] parm = new SqlParameter[5];
            {
                parm[0] =new SqlParameter(){ Direction= ParameterDirection.Input,ParameterName="@compute_code",Value=compute_code,DbType= DbType.String};
                parm[1] = new SqlParameter(){Direction=  ParameterDirection.Input,ParameterName="@tax_ny",Value=tax_ny,DbType= DbType.String};
                 parm[2] =new SqlParameter(){Direction= ParameterDirection.Input,ParameterName="@tax_type", Value= tax_type ,DbType= DbType.Int32};
                 parm[3] = new SqlParameter() { Direction = ParameterDirection.Input, ParameterName = "@tax_money", Value = tax_money, DbType = DbType.Decimal };
                
            };
            SqlParameter resultParm= new SqlParameter(){Direction= ParameterDirection.Output,ParameterName="@result",DbType= DbType.Int32};
            parm[4]=resultParm;
            DbHelperSQL.RunProcedure("up_setTaxInfo",parameters:parm);
            result = Convert.ToInt32( resultParm.Value.ToString());
            return result>0;
        }

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(Taxes.Model.tax_info model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into tax_info(");
			strSql.Append("compute_code,tax_ny,tax_type,tax_money)");
			strSql.Append(" values (");
			strSql.Append("@compute_code,@tax_ny,@tax_type,@tax_money)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@compute_code", SqlDbType.Char,9),
					new SqlParameter("@tax_ny", SqlDbType.Char,6),
					new SqlParameter("@tax_type", SqlDbType.Int,4),
					new SqlParameter("@tax_money", SqlDbType.Decimal,9)};
			parameters[0].Value = model.compute_code;
			parameters[1].Value = model.tax_ny;
			parameters[2].Value = model.tax_type;
			parameters[3].Value = model.tax_money;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Taxes.Model.tax_info model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update tax_info set ");
			strSql.Append("compute_code=@compute_code,");
			strSql.Append("tax_ny=@tax_ny,");
			strSql.Append("tax_type=@tax_type,");
			strSql.Append("tax_money=@tax_money");
			strSql.Append(" where ID=@ID");
			SqlParameter[] parameters = {
					new SqlParameter("@compute_code", SqlDbType.Char,9),
					new SqlParameter("@tax_ny", SqlDbType.Char,6),
					new SqlParameter("@tax_type", SqlDbType.Int,4),
					new SqlParameter("@tax_money", SqlDbType.Decimal,9),
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = model.compute_code;
			parameters[1].Value = model.tax_ny;
			parameters[2].Value = model.tax_type;
			parameters[3].Value = model.tax_money;
			parameters[4].Value = model.ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from tax_info ");
			strSql.Append(" where ID=@ID");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)
};
			parameters[0].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from tax_info ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Taxes.Model.tax_info GetModel(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ID,compute_code,tax_ny,tax_type,tax_money from tax_info ");
			strSql.Append(" where ID=@ID");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)
};
			parameters[0].Value = ID;

			Taxes.Model.tax_info model=new Taxes.Model.tax_info();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					model.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["compute_code"]!=null && ds.Tables[0].Rows[0]["compute_code"].ToString()!="")
				{
					model.compute_code=ds.Tables[0].Rows[0]["compute_code"].ToString();
				}
				if(ds.Tables[0].Rows[0]["tax_ny"]!=null && ds.Tables[0].Rows[0]["tax_ny"].ToString()!="")
				{
					model.tax_ny=ds.Tables[0].Rows[0]["tax_ny"].ToString();
				}
				if(ds.Tables[0].Rows[0]["tax_type"]!=null && ds.Tables[0].Rows[0]["tax_type"].ToString()!="")
				{
					model.tax_type=int.Parse(ds.Tables[0].Rows[0]["tax_type"].ToString());
				}
				if(ds.Tables[0].Rows[0]["tax_money"]!=null && ds.Tables[0].Rows[0]["tax_money"].ToString()!="")
				{
					model.tax_money=decimal.Parse(ds.Tables[0].Rows[0]["tax_money"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,compute_code,tax_ny,tax_type,tax_money ");
			strSql.Append(" FROM tax_info ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,compute_code,tax_ny,tax_type,tax_money ");
			strSql.Append(" FROM tax_info ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "tax_info";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

